/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ntb.controllers;

import com.ntb.entities.Contact;
import com.ntb.models.ContactDAO;
import com.ntb.models.impl.ContactDAOImpl;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Thinh Hung
 */
public class SendContactAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) {
        PrintWriter out = null;
        try {
            String name = request.getParameter("name");
            String email = request.getParameter("email");
            String comment = request.getParameter("comment");
            Contact contact = new Contact();
            contact.setName(name);
            contact.setEmail(email);
            contact.setMessage(comment);
            ContactDAO contactDao = new ContactDAOImpl();
            contactDao.add(contact);
            /*
            String content = "<b>Name</b>: " + name + "<br/><br/>" +
                    "<b>Email</b>: " + email + "<br/><br/>" +
                    "<b>Message</b>: " + comment;
            MailUtil mailUtil = new MailUtil();
            mailUtil.sendMail("A message have been sent from NTB!", content);
             */
            response.setContentType("text/html");
            out = response.getWriter();
            out.println("1");
            out.flush();
        } catch (IOException ex) {
            Logger.getLogger(SendContactAction.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            out.close();
        }
        return null;
    }
}
